package chapter6.meine;

import java.awt.Canvas;
import java.awt.Color;
import java.awt.Frame;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class DrawRectsOnClickCanvas extends Canvas{
	int x,y;
	
	public DrawRectsOnClickCanvas (){
		super();
		setBackground(Color.black);
		addMouseListener(new MouseListener() {
			
			
			@Override
			public void mouseReleased(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mousePressed(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseExited(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseEntered(MouseEvent arg0) {
				// TODO Auto-generated method stub
				
			}
			
			@Override
			public void mouseClicked(MouseEvent e) {
				x=e.getX();
				y=e.getY();	
				Graphics gg = getGraphics();
				gg.setColor(Color.RED);
				gg.fillRect(x, y, 30, 20);
				gg.drawOval(x, y, 20, 10);
							
			}

		});
		}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		final Frame f = new Frame("Draw Rects On Click");
		   f.addWindowListener(new WindowAdapter() {
		         public void windowClosing(WindowEvent e) {
		            f.dispose();
		         }
		      });
		   final DrawRectsOnClickCanvas d = new DrawRectsOnClickCanvas();
	      f.add(d);
	      f.setSize(400, 300);

	      f.setVisible(true);
		// TODO Auto-generated method stub

	}

}
